﻿$(function () {

    $("#btnSubmitJoin").live("click", btnSubmitJoinClick);
    $("#btnSubmitJapanJoin").live("click", btnSubmitJapanJoinClick);
    
    var info = $("#hiddenInfo").val();
    if (info == "true") {
        //location.reload();
        alert("提交成功");
    } else
        if ($.trim(info) != "") {
            alert(info);
        }

    $("#spanProviceCity").chinaprovinces({
        valueType: 'name', change: function (province, city, area) {
            $("#AddressProvice").val(province);
            $("#AddressCity").val(city);
            $("#AddressZone").val(area);
        }
    });

    function btnSubmitJoinClick()
    {
        var res = true;
        var $inputs = $("#FranchiseForm :input").not(".notNeedInput");
        for (var i = 0; i < $inputs.length; i++) {
            var $unit = $($inputs[i]);
            if ($unit.val() == "" || $unit.val() == undefined) {
                var info = $("label[for='" + $unit.attr("id") + "']").text();
                alert("请填写正确的：" + info);
               // alert($unit.attr("id"));
                $unit.focus();
                res = false;
                break;
            }
        };
        if (res) {
            $("#FranchiseForm").submit();
        }
    }


    function btnSubmitJapanJoinClick() {
        var res = true;
        var $inputs = $("#FranchiseForm :input").not(".notNeedInput");
        for (var i = 0; i < $inputs.length; i++) {
            var $unit = $($inputs[i]);
            if ($unit.val() == "" || $unit.val() == undefined) {
                var info = $("label[for='" + $unit.attr("id") + "']").text();
                alert("请填写正确的：" + info);
                // alert($unit.attr("id"));
                $unit.focus();
                res = false;
                break;
            }
        };
        if (res) {
            $("#FranchiseForm").submit();
        }
    };

    $("#selectNeedWorkType").change(function () {
        var strWorkType = selectMultiple();
        $("#NeedWorkType").val(strWorkType);
    });
    function selectMultiple() {
        var o = document.getElementById("selectNeedWorkType");
        var str = "";
        for (i = 0; i < o.length; i++) {
            if (o.options[i].selected) {
                str += o.options[i].value + ",";
            }
        }
        return str.substr(0, str.length - 1);
    }
});